<include file="Public:header" />
<form name="myform" id="myform" method="POST" action="__ACTION__">
	<input name="data[id]" type="hidden" value="{$info['id']}">
  <fieldset>
    <legend>基本信息</legend>
    <table class="table_form" width="100%" cellspacing="0">
      <tbody>
      	<tr>
          <th width="60">联系人：</th>
          <td><input type="text" name="data[name]" id="name" size="20"  value="{$info.name}" class="input-text"  /></td>
        </tr>
        <tr>
          <th>联系电话：</th>
          <td><input type="text" name="data[phone]" id="phone" size="20"  value="{$info.phone}" class="input-text"  /></td>
        </tr>
        <tr>
          <th>区域：</th>
          <td>
          <input name="data[provinceName]" id="provinceName" type="hidden" value="{$info.provinceName}">
          <input name="data[cityName]" id="cityName" type="hidden" value="{$info.cityName}">
          <input name="data[areaName]" id="areaName" type="hidden" value="{$info.areaName}">
            <select name="data[province]" id="province">
            	<option value="0">请选择所属省份</option>
              	<volist name="provinceList" id="vo">
              	<option value="{$vo.id}"  />{$vo.name}</option>
              	</volist>
            </select>
            <span style="margin-left:20px;">所属城市：</span>
            <select name="data[city]" id="city">
            	<option value="0">请选择所属城市</option>
              	<volist name="cityList" id="vo">
              	<option value="{$vo.id}" />{$vo.name}</option>
              	</volist>
            </select>
            <span>所属区域：</span>
            <select name="data[area]" id="area">
            	<option value="0">请选择所属区域</option>
              	<volist name="areawList" id="vo">
              	<option value="{$vo.id}"  />{$vo.name}</option>
              	</volist>
            </select>
            </td>
        </tr>
        <tr>
          <th>性别：</th>
           <td>
          	<input name="sex" type="radio" value="1" checked="checked" >男&nbsp;&nbsp;
            <input name="sex" type="radio" value="0" <eq name="info.sex" value="0"> checked </eq> >女
          </td>
        </tr>
        <tr class="last">
          <th>所属分组：</th>
          <td>
          	<select name="data[group_id]" id="groupId">
            <option value="0" selected="selected" />未分组</option>
              <volist name="groupList" id="vo"> 
              <option value="{$vo.id}" />{$vo.name}</option>
              </volist>
            </select>
          </td>
        </tr>
      </tbody>
    </table>
  </fieldset>
  <input type="submit" value="提交" class="dialog" id="dosubmit">
</form>
</body>
</html>
<script type="text/javascript" src="/Public/Js/ueditor/ueditor.config.js"></script>	<!--ueditor编辑器-->
<script type="text/javascript" src="/Public/Js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/My97DatePicker/WdatePicker.js"></script>

<script type="text/javascript">
$(function(){
	var groupId = "{$info.group_id}";
	$("#groupId").val(groupId);
	
	var province = "{$info.province}";
	$("#province").val(province);
	var city = "{$info.city}";
	$("#city").val(city);
	var area = "{$info.area}";
	$("#area").val(area);
	
	$('#myform').ajaxForm({
		beforeSubmit:  checkForm,
		success:       complete,
		dataType: 'json'
	});
	function checkForm(){
		var name = $("#name").val();
		var phone = $("#phone").val();
		var content = $("#content").val();
		if(name==''){
			msg('联系人不能为空！',0);
			return false;
		}
		if(phone==''){
			msg('电话号码不能为空！',0);
			return false;
		}
		if(content==''){
			msg('请填写电话内容！',0);
			return false;
		}
		return true;
	}
	var origin = $.artDialog.open.origin;
    function complete(data){
    	msg(data.info,data.status);
		if(data.status) setTimeout(function(){origin.location.reload();},1000);
    }
	
	
	$(".linkmanInfo").hide();
	$("#search").click(function(){
		var keyword = $("#keyword").val();
		$("#linkmanList").empty();
		$.get("__URL__/getContacts", { keyword: keyword},function(data){
			$("#linkmanList").append("<option value=\"0\">请选择联系人</option>");
			var list = data.data;
			jQuery.each(list, function(i,val) {
					$("#linkmanList").append("<option value=\""+val.id+"\">"+val.name+"("+val.phone+")</option>");
			});
	   });
	})
	
	$("#linkmanList").change(function(){
		var id = $(this).val();
		$(".linkmanInfo").show();
		$.get("__URL__/getContactsInfo", { id: id},function(data){
			var info = data.data;
			$("#name").text(info.name);
			$("#sex").text(info.sexName);
			$("#phone").text(info.phone);
			$("#tel").text(info.tel);
			$("#address").text(info.address);
			
			$("#name").next("input").val(info.name);
			$("#sex").next("input").val(info.sex);
			$("#phone").next("input").val(info.phone);
			$("#tel").next("input").val(info.tel);
			$("#address").next("input").val(info.address);
	   });
	})
	
})
</script>
<script>
$(document).ready(function(){
	$('#province').live('change', function() {
		var provinceName = $('#province :selected').text();
		$("#provinceName").val(provinceName);
		var pid = $("#province option:selected").val();
		var href='__APP__/Area/ajaxCityList/randNum/'+Math.random();
		$("#city").empty();
		$("#area").empty();
		jQuery.ajax({ 
			type:'GET', 
			url:href, 
			dataType:'text', 
			data:encodeURI('pid='+pid),
			error: function(){ //如果出错，执行函数   
				alert('Error loading XML document');   
			},
			success:function(data){
				var jsondata = eval("("+ data+")");
				var arrLength = jsondata.data.length;
				jQuery("#city").append("<option value=\"0\">请选择城市</option>");
				for(var i=0; i<arrLength; i++){
					jQuery("#city").append("<option value=\""+jsondata.data[i]['id']+"\">"+jsondata.data[i]['name']+"</option>");
				}
				jQuery("#area").append("<option value=\"0\">请选择区域</option>");
			} 
		});
	});
	
	$('#city').live('change', function() {
		var cityName = $('#city :selected').text();
		$("#cityName").val(cityName);
		var cid = $("#city option:selected").val();
		var href='__APP__/Area/ajaxAreaList/randNum/'+Math.random();
		$("#area").empty();
		jQuery.ajax({ 
			type:'GET', 
			url:href, 
			dataType:'text', 
			data:encodeURI('cid='+cid),
			success:function(data){
				var jsondata = eval("("+ data+")");
				jQuery("#area").append("<option value=\"0\">"+jsondata.info+"</option>");
				if(jsondata.status!=0){
					var arrLength = jsondata.data.length;
					for(var i=0; i<arrLength; i++){
						jQuery("#area").append("<option value=\""+jsondata.data[i]['id']+"\">"+jsondata.data[i]['name']+"</option>");
					}
				}
			} 
		});
	});
	
	$("#area").change(function(){
		var areaName = $('#area :selected').text();
		$("#areaName").val(areaName);
	})
  
});
</script>
<script type="text/javascript">
UE.getEditor('content',{
	//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
	//toolbars:[['FullScreen', 'Source', 'Undo', 'Redo','Bold','test']],
	//focus时自动清空初始化时的内容
	autoClearinitialContent:false,
	//关闭字数统计
	wordCount:false,
	//关闭elementPath
	elementPathEnabled:false,
	//默认的编辑区域高度
	initialFrameHeight:220
	//更多其他参数，请参考ueditor.config.js中的配置项
})
</script>
